home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / mkdep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-10  |  1.2 KB  |  66 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. char include[] = "#include";
  6.  
  7. main(argc,argv)
  8. int argc;
  9. char *argv[];
  10. {
  11.     FILE *fin, *fout, *fwork;
  12.     char ext[20], buf[512], *cp, *cp1;
  13.  
  14.     if(argc < 3 || argc > 4) {
  15.         printf("mkdep.exe - syntax: mkdep <infile> <outfile> [ext]\n");
  16.         exit(1);
  17.         return 0;
  18.     }
  19.  
  20.     if((fin = fopen(argv[1],"r")) == NULL
  21.       || (fout = fopen(argv[2],"w")) == NULL) {
  22.         printf("File reading/creating error\n");
  23.         exit(1);
  24.         return 0;
  25.     }
  26.  
  27.     if(argc > 3)
  28.         strcpy(ext,strlwr(argv[3]));
  29.     else
  30.         strcpy(ext,".c");
  31.  
  32.     while(fgets(buf,512,fin) != NULL) {
  33.         if((cp = strchr(buf,' ')) == NULL)
  34.             continue;
  35.         *cp = '\0';
  36.  
  37.         strlwr(buf);
  38.         fprintf(fout,"%s.obj: %s%s",buf,buf,ext);
  39.  
  40.         strcat(buf,ext);
  41.  
  42.         if((fwork = fopen(buf,"r")) == NULL) {
  43.             printf("Unable to open file %s\n",buf);
  44.             continue;
  45.         }
  46.         while(fgets(buf,512,fwork) != NULL){
  47.             if(strncmp(buf,include,sizeof(include)-1) != 0)
  48.                 continue;
  49.             if((cp = strchr(buf,'\"')) == NULL)
  50.                 continue;
  51.             cp++;
  52.             if((cp1 = strchr(cp,'\"')) == NULL)
  53.                 continue;
  54.             fputc(' ',fout);
  55.             while(cp != cp1)
  56.                 fputc(*cp++,fout);
  57.         }
  58.         fputc('\n',fout);
  59.         fflush(fout);
  60.         fclose(fwork);
  61.     }
  62.     fclose(fin);
  63.     fclose(fout);
  64.     return 0;
  65. }
  66.